`define IMM_I_TYPE  3'b000
`define IMM_S_TYPE  3'b001
`define IMM_B_TYPE  3'b010

module imm_gen (
  input [31:0] instr,
  input [2:0]  imm_ctrl,
  output reg [31:0] imm
);
  
  always @(*) begin
    case(imm_ctrl)
      `IMM_I_TYPE:  imm <= {{20{instr[31]}}, instr[31:20]};   
      `IMM_S_TYPE:  imm <= {{20{instr[31]}}, instr[31:25], instr[11:7]};
      `IMM_B_TYPE:  imm <= {{20{instr[31]}}, instr[7], instr[30:25], instr[11:8], 1'b0};
      default:      imm <= 32'b0;
    endcase
  end

endmodule